package com.xvyy.tingshu.user.rpc;

import com.xvyy.tingshu.common.result.Result;
import com.xvyy.tingshu.model.user.UserInfo;
import com.xvyy.tingshu.model.user.VipServiceConfig;
import com.xvyy.tingshu.user.service.UserInfoService;
import com.xvyy.tingshu.user.service.VipServiceConfigService;
import com.xvyy.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName: UserInfoRpcController
 * Package: com.xvyy.tingshu.user.rpc
 *
 * @Description:
 * @Author: xvyy
 * @Create: 2025/1/19 - 15:18
 * @Version: v1.0
 */
@RestController
@RequestMapping("/api/rpc/userinfo")
public class UserInfoRpcController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private VipServiceConfigService vipServiceConfigService;

    @GetMapping("/getUserinfo/{userId}")
    @Operation(summary = "获取用户的基本信息")
    Result<UserInfoVo> getUserInfo(@PathVariable(value = "userId") Long userId) {

        UserInfoVo userInfoVo = userInfoService.getUserInfoVo(userId);
        return Result.ok(userInfoVo);
    }

    @GetMapping("/getUserPaidAlbumTrackList/{userId}/{albumId}")
    @Operation(summary = "获取该购买专辑下的声音列表")
    Result<Map<Long, String>> getUserPaidAlbumTrackList(
            @PathVariable(value = "userId") Long userId,
            @PathVariable(value = "albumId") Long albumId) {
        Map<Long, String> trackListMap = userInfoService.getUserPaidAlbumTrackList(userId, albumId);
        return Result.ok(trackListMap);
    }

    @GetMapping("/getUserPaidAlbum/{userId}/{albumId}")
    @Operation(summary = "获取该购买专辑下的声音列表")
    Result<Boolean> getUserPaidAlbum(
            @PathVariable(value = "userId") Long userId,
            @PathVariable(value = "albumId") Long albumId) {
        Boolean isPaid = userInfoService.getUserPaidAlbum(userId, albumId);
        return Result.ok(isPaid);
    }

    @GetMapping(value = "/getAllVipConfig/{itemId}")
    @Operation(summary = "获取所有vip配置")
    Result<VipServiceConfig> getAllVipConfig(@PathVariable(value = "itemId") Long itemId) {
        VipServiceConfig vipServiceConfig = vipServiceConfigService.getById(itemId);
        return Result.ok(vipServiceConfig);
    }

    @GetMapping(value = "/updateUserVip/")
    @Operation(summary = "更新用户的vip信息")
    Result<UserInfo> updateUserVip(@RequestBody UserInfo userInfo) {
        UserInfo userInfoResult = userInfoService.updateUserVip(userInfo);
        return Result.ok(userInfoResult);
    }


    @GetMapping(value = "/updateVipExpireStatus/")
    @Operation(summary = "更新用户的vip信息")
    Result updateVipExpireStatus() {
        userInfoService.updateVipExpireStatus();
        return Result.ok();
    }


}
